package it.univaq.mancoosi.injectors.systemconfiguration.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProcessCommand {

	static private ProcessCommand processCommandInstance = null;
	private Runtime runtime;
	
	protected ProcessCommand() {
		runtime = Runtime.getRuntime();
	}

	static public ProcessCommand getInstance() {
		if(null == processCommandInstance) {
			processCommandInstance = new ProcessCommand();
		}
		return processCommandInstance;
	}

	public BufferedReader getResult(String[] cmd){
		BufferedReader input = null;
		
		try {
			Process p = getInstance().runtime.exec(cmd);
			input = new BufferedReader(new InputStreamReader(p.getInputStream()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return input;
	}
	
	
	public BufferedReader getErrorSream(String[] cmd){
		BufferedReader input = null;
		
		try {
			Process p = getInstance().runtime.exec(cmd);
			input = new BufferedReader(new InputStreamReader(p.getErrorStream()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return input;
	}
}
